<template>
  <PagingTable ref="pagingTable" :options="options" :querys="querys">
    <template slot="data-columns">
			
			<el-table-column label="考试科目" align="center" >
        <template slot-scope="scope">
					<span>{{subjectMap[scope.row.suject]}}</span>
        </template>
      </el-table-column>

      <el-table-column label="时间" prop="time" show-overflow-tooltip :formatter="formatDate"/>

      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-button icon="el-icon-caret-right" type="primary" size="mini" @click="handlePre(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </template>
  </PagingTable>
</template>

<script>
import PagingTable from '@/components/PagingTable'
import request from '@/request'

export default {
  name: 'ExamHistory',
  components: { PagingTable },
  data() {
    return {
			querys: {
				uid: 1,
			},
			subjectMap: {},
      options: {
        controllerUrl: '/exam', // 列表请求URL
      }
    }
  },
	mounted() {
		request({
			method: 'post', url: '/subject/query',
			data: { current: 1, size: 100, params: null }
		}).then(resp=>{
			var that = this
			resp.data.data.records.map(subject=>{
				that.subjectMap[subject.id] = subject.name
			})
		})
	},
  methods: {
    getFormatDateTime(date){
      var year= date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      var hour = date.getHours();
      var minute = date.getMinutes();
      var second = date.getSeconds();
      return [year, '-', month , '-', day, ' ', hour , ':', minute, ':', second ].join('');
    },
		formatDate(row){
			return this.getFormatDateTime(new Date(row.time))
		},
    // 开始考试
    handlePre(row) {
      this.$router.push({ name: 'ExamResult', params: { id: row.id, name: this.subjectMap[row.suject] }})
    }
  }
}
</script>
